package com.iflytek.amr;

import android.content.Context;
import android.media.MediaExtractor;
import android.media.MediaFormat;

import androidx.annotation.NonNull;

import java.io.IOException;

/**
 * @ClassName AudioEncoder
 * @Description TODO
 * @Author zdl
 * @Date 2021/3/8 12:44
 * @Version 1.0
 */
public abstract class AudioEncoder {


    protected int SAMPLE_RATE = 8000;
    protected int BIT_RATE = 64;
    protected int CHANNEL_COUNT = 1;
    protected String destinationFile;

    public void init(Context context,int SAMPLE_RATE, int BIT_RATE, int CHANNEL_COUNT) {
        this.SAMPLE_RATE = SAMPLE_RATE;
        this.BIT_RATE = BIT_RATE;
        this.CHANNEL_COUNT = CHANNEL_COUNT;
    }


    public void init(Context context) {
    }



    public String getDestFile() {
        return destinationFile;
    }

    @NonNull
    protected MediaFormat getMediaFormat(String sourceFile) throws IOException {
        MediaExtractor mex = new MediaExtractor();
        mex.setDataSource(sourceFile);
        return mex.getTrackFormat(0);
    }

    public abstract void encode(String sourceFile);
}
